<cfif IsDefined("session.id")>
	<cfif Not IsDefined("GroupName")>
		<cfset GroupName = gn>
	</cfif>
	<cfparam name="URL.gn" default="">
	<cfparam name="GroupName" default="#gn#">
	<cftry>
		<cftransaction>
			<cfquery datasource="exp" result="res">

				INSERT INTO groups (name, ownerID, description)
				VALUES (<cfqueryparam cfsqltype="cf_sql_varchar" value="#GroupName#">, #session.id#, '')

			</cfquery>
			<cfquery datasource="exp">
			
				INSERT INTO groupusers (UserID, GroupID)
				VALUES (#session.id#, #res.GENERATED_KEY#)

			</cfquery>
		</cftransaction>
		<cfset session.message ="Group added sucessfully!">
		<cfcatch type="Database">
			<cfset session.message ="Group already exists! -- #res.GENERATED_KEY#">
		</cfcatch>
	</cftry>
	<cflocation url="/ecada/Grouping/ListGroups.cfm">
	<cfabort>
<cfelse>
	<cflocation url="/ecada/index.cfm">
	<cfabort>
</cfif>
